import java.io.*;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Galen.liu
 * 实现Fac文件读取，去掉不需要的字符，转换为csv文件
 */
public class FacToCsv {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new FileReader(args[0]));
        //"src/main/resources/Mapping_19.fac"
        String str = args[0];
        int startIndex = str.lastIndexOf("/") + 1;
        int facIndex = str.lastIndexOf("fac");
        String out = "./" + str.substring(startIndex, facIndex) + "csv";
        BufferedWriter bw = new BufferedWriter(new BufferedWriter(new FileWriter(out)));
        String line = null;
        while ((line = br.readLine()) != null) {
            if (line.startsWith("!")) {
                bw.write(line);
            }
            if (line.startsWith("*")) {
                bw.newLine();
                bw.write(line);
            }
        }
        bw.close();
        System.out.println(str.substring(startIndex, facIndex-1)+".csv已经生成在同级目录");
    }
}
